// Copyright  Author(https://github.com/LiuShuKu). All Rights Reserved.

// Copyright (c)  2024 LiuShuKu
// Project Name :   balance
// Author       :   liushuku@yeah.net

// Package tron .
package tron

import (
	"fmt"
	"github.com/gogf/gf/v2/net/gclient"
	"github.com/gogf/gf/v2/util/grand"
	"time"
)

const (
	// TRON 波场地址
	tronScanHttpLink = "https://apilist.tronscanapi.com/api"
)

var (
	// tronScanApi 秘钥
	tronHttpAppKeys = []string{
		"fdf5e4fd-611b-4988-ab58-dca3c6dfb24b",
		"b6e0377c-a61c-463e-9b4b-a55db586771d",
		"ac2184db-8c0e-4ba2-93ec-82f9280f66a6",
		"47a7eada-2d33-40be-b363-30c40c8482ca",
		"546a83a1-8b67-4697-8c84-4f59e5700890",
		"e2a4e1ce-eb79-47ea-a70f-17829f529d22",
		"528fda64-cc8b-4b26-802a-27b36a0feb7f",
		"e5973659-3456-46a5-a292-a48d23a84a75",
		"2ed4f24b-50ec-488d-bc42-f0eb7d088a76",
		"efd687cf-b521-4511-ba49-a3e0adcab565",
		"0597f577-9bc7-484a-9c5d-a46a8a372972",
		"7d0b2a6a-9fb8-4494-9b8c-fc2225204e1e",
		"f5854b3f-6101-4f4d-ae73-b1470d80bf19",
		"8e193b2d-62a2-495b-a31a-9f233a0def72",
		"76e82f16-6f29-443b-bd80-2a83f7b1afcf",
		"b4da3d9e-a2e7-4a9b-b410-3b5ddc3715b5",
		"35cc6bb6-15bc-41d0-a414-bbc26c528bb4",
		"5cfa59f0-bf35-46a3-8737-e97cfcc4135d",
		"935dda79-dc26-40d7-ae80-6ab34616a3f6",
		"35f39940-a5a2-4a2b-8bc6-30d1e1d24cea",
		"4767260c-62d0-490c-b684-dceca021588d",
	}
)

type http struct {
	url  string
	http *gclient.Client
}

var tronHttp = &http{}

// connect 获取连接
func (t *http) connect(timeout ...time.Duration) *http {
	key := t.getTronProApiKey()
	t.url = tronScanHttpLink
	t.http = gclient.New().SetHeader("TRON-PRO-API-KEY", key)
	if len(timeout) > 0 {
		t.http.SetTimeout(timeout[0])
	}
	return t
}

// getTronProApiKey 获取秘钥-随机获取
func (t *http) getTronProApiKey() (apiKey string) {
	// 创建随机数生成器
	randomIndex := grand.N(0, len(tronHttpAppKeys)-1)
	// 随机获取数组中的数据
	randomData := tronHttpAppKeys[randomIndex]
	{
		apiKey = randomData
	}
	fmt.Println(apiKey)
	return
}
